<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/common/header.jsp"%>
<c:set var="path" value="..${ctx}/define/menu"/>
<div class="pageContent">
	<form name="define_menu_edit" method="post" action="${path}/save.html" class="pageForm required-validate" onsubmit="return validateCallback(this, dialogAjaxDone2);">
		<div class="pageFormContent" layoutH="56">
			<fieldset>
				<dl>
					<dt>菜单编号：</dt>
					<dd><input name="id" type="text" size="30" value="${group.id}" readonly="readonly"/>
						<input name="parentID" type="hidden" value="${parentID}" />
					</dd>
				</dl>
				<dl>
					<dt>菜单名称：</dt>
					<dd><input name="text" type="text" size="30" value="${group.text}" class="required" /></dd>
				</dl>
				<dl>
					<dt>菜单代码：</dt>
					<dd><input name="code" type="text" size="30" value="${group.code}" /></dd>
				</dl>
				<dl>
					<dt>操作名称：</dt>
					<dd>
					<input name="actionName" type="text" size="30" value="${group.actionName}" />
					<a class="btnLook" href="javascript:openActionConsult();">查找带回</a>
					</dd>
				</dl>
				<dl>
					<dt>操作类型：</dt>
					<dd>
						<select class="combox" name="openType" >
							<option value="window" <c:if test="${group.openType=='window'}">selected</c:if> >窗体</option>
							<option value="dialog" <c:if test="${group.openType=='dialog'}">selected</c:if> >对话框</option>
							<option value="message" <c:if test="${group.openType=='message'}">selected</c:if>>消息框</option>
						</select>
					</dd>
				</dl>
				<dl>
					<dt>排序：</dt>
					<dd>
						<input name="sort" type="text" size="30" class="digits" value="${group.sort}" />
					</dd>
				</dl>
				<dl>
					<dt>视图名称：</dt>
					<dd><input name="view" type="text" size="30" value="${group.view}" /></dd>
				</dl>
				<dl class="nowrap">
					<dt>权限配置：</dt>
					<dd>
					<c:set var="desc" value="" />
					<c:if test="${! empty group.judge}">
						<c:if test="${! empty group.judge.judges}">
							<c:forEach var="data" items="${group.judge.judges}">
								<c:set var="desc" value="${data};${desc}" />
							</c:forEach>
						</c:if>
					</c:if>
					<textarea id="judgement" cols="50" rows="3"><c:out value="${desc}" /></textarea>
					<a class="btnLook" href="javascript:openJudgeConsult();">查找带回</a>
					</dd>
				</dl>
				<dl class="nowrap">
					<dt>描述：</dt>
					<dd>
					<textarea id="description" name="description" cols="50" rows="3"><c:out value="${group.description}" /></textarea>
					</dd>
				</dl>
			</fieldset>
			
		</div>
		<div class="formBar">
			<ul>
				<!--<li><a class="buttonActive" href="javascript:;"><span>保存</span></a></li>-->
				<li><div class="buttonActive"><div class="buttonContent"><button type="submit" >保存</button></div></div></li>
				<li>
					<div class="button"><div class="buttonContent"><button type="button" class="close">关闭</button></div></div>
				</li>
			</ul>
		</div>
	</form>
</div>
<script type="text/javascript">
/**
 * dialog上的表单提交回调函数
 * 服务器转回navTabId，可以重新载入指定的navTab. statusCode=DWZ.statusCode.ok表示操作成功, 自动关闭当前dialog
 * form提交后返回json数据结构,json格式和navTabAjaxDone一致
 */
function dialogAjaxDone2(json){
	DWZ.ajaxDone(json);
	if (json.statusCode == DWZ.statusCode.ok){
		// alert(json.callbackType);
		if(json.callbackType){
			navTab.reload("${path}/list.html");//刷新
			setTimeout(function(){$.pdialog.closeCurrent();}, 100);
		}
	}
}

function openActionConsult(){
	var title = "选择操作";
	var url = "..${ctx}/define/action/consult.html?js_back_function=consultActionBack";
	$.pdialog.open(url, "define_menu_action_consult", title,{width:800,height:480,mask:true,maxable:false,resizable:false});
}

function consultActionBack(args){
	$("input[name='actionName']").val(args);
	$.pdialog.close("define_menu_action_consult");
	return;
	var params = $(define_menu_list).serialize();
	// serialize()自动调用了encodeURIComponent方法将数据编码了
	// 调用decodeURIComponent(XXX,true);将数据解码
	params = decodeURIComponent(params,true);
	// 将值部分二次转码，以防出现中文乱码的问题
	params = convertUTF8(params,"actionName");
	params = params + "&actionName=" + encodeURI(encodeURI(args));
	var url = "${path}/saveTemp.html?" + params;
	// 关闭子参照窗体
	$.pdialog.close("define_menu_action_consult");
	// 重新打开本窗体
	$.pdialog.open(url, "base_define_action_add", "菜单",{width:800,height:480,mask:true,maxable:false,resizable:false});
}

/**
 * 将URL请求参数中值的部分二次转码，以防出现中文乱码
 * 例：actionType=&name=q&sort=q&description=q&dwz_rowNum=1&items.key%5B0%5D=q
 */
function convertUTF8(args,exp){
	var params = "";
	var arr = args.split("&");
	for(var s in arr){
		var array = arr[s].split("=");
		if(array[1] != ""){
			if(array[0] != exp){
				//alert(arr[0] + '=' + exp);
				params = params + '&' + array[0] + '=' + encodeURI(encodeURI(array[1]));
			}
		}
	}
	return params.substr(1);
}

function openJudgeConsult(){
	var title = "选择操作";
	var url = "..${ctx}/define/judge/list.html?jsbackfunctionname=menuJudgeConsultBack";
	$.pdialog.open(url, "define_menu_judge_list", title,{width:500,height:420,mask:true,maxable:false,resizable:false});
}

function menuJudgeConsultBack(){
	var url = "${path}/getJudgeDescriptions.html";
	$.ajax({
		type: "post", url: url,
		success: function(data){
			var json = JSON.parse(data);
			$("#judgement").val(json.message);
		},
		error: function(){
			alertMsg.error('系统错误，请联系管理员！');
		}
	});
}
</script>